package org.example;
import lombok.RequiredArgsConstructor;
import org.example.dto.CourseDto;
import org.example.dto.CourseRequestDto;
import org.example.dto.PageDto;
import org.example.dto.ResultDto;
import org.example.service.CourseService;
import org.springframework.web.bind.annotation.*;


@RestController
@RequiredArgsConstructor
public class CourseController {               //消费者模块
    private final CourseService courseService;

    /**
     * 接收路径参数
     * @param account
     * @param page
     * @param rows
     * @return
     */
    @GetMapping("/courses/{account}/{page}/{rows}")
    public ResultDto<PageDto<CourseDto>> queryCourse(@PathVariable("account") String account,
                                                     @PathVariable("page") Integer page,
                                                     @PathVariable("rows") Integer rows){
        return courseService.findCourseByPath(account, page, rows);

    }

    /**
     * 接收JSON类型的参数
     * @param course
     * @return
     */
    @PostMapping("/courses")
    public ResultDto<PageDto<CourseDto>> findCourse(@RequestBody CourseRequestDto course){
        return courseService.findCourseByJson(course);
    }

    /**
     * 接收FROM参数
     * @param course
     * @return
     */
    @PostMapping("/courses1")
    public ResultDto<PageDto<CourseDto>> findCourse1(CourseRequestDto course){
        return courseService.findCourseByForm(course);
    }


}
